home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
bbsutil
/
hsrc_117.zip
/
MAILIN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-08
|
18KB
|
680 lines
/* Tosser for net/echo mail */
#include "msgg.h"
#include "twindow.h"
#include "keys.h"
#include "headedit.h"
#define MAXKLUDGE 133
static ulong totalmsgs=0;
static word *anum; /* Pointer to area # msgs array */
static word pmnum; /* # messages in packet */
static struct _pkthdr pi; /* The current incoming packet's header */
static struct _xmsg xmsg; /* The current msg's header */
static char *text; /* Pointer to current msg's text body */
static char *pathline; /* Pointer to current msg's PATH line(s) */
static char *seenby; /* Pointer to current msg's SEEN-BY line(s) */
static char *area; /* Pointer to current msg's AREA: tag */
static char *kludge; /* Pointer to first kludge line in msg */
static char *endptr; /* End-of-msg pointer */
static char *arcext[]={"MO","TU","WE","TH","FR","SA","SU",NULL};
static char mailerless;
char no_strip=0; /* Don't remove EID's & SEENBYs if > 0 */
char no_fillin=0; /* Don't complete addresses from kludges if > 0 */
/* Function declarations */
void pascal import_mail(void);
FILE * pascal open_pkt (word zone,word net,word dest,word d_point,char *domain,word attr,word m_attr);
void pascal close_pkt (FILE *fp);
static void pascal close_msg_files(void);
int pascal write_pkt_msg (FILE *fp,struct _xmsg *amsg,char *text,char *area);
static int pascal are_we_in_here (char *buf,word net,word node);
static int pascal crack_pkt (char *pktname);
static int pascal crack_arc (char *in, char *arcname);
static int pascal import (void);
static int pascal move_2_safety (char *pktname);
static int pascal unknown_msg ();
static int pascal get_msg (word buflen,char *buffer,FILE *fp);
static void pascal report(void);
void pascal import_mail (void) {
register int x;
word areanum[4096];
struct ffblk f;
char s[133];
char ss[133];
printf("\x1b[2J");
if(!*inbound) {
printf("\07I don't know where your Inbound directory is!\n");
return;
}
anum=areanum; /* So it can be accessed globally */
printf("\nImporting mail...");
for(x=0;x<4096;x++) {
anum[x]=0;
}
if(!netboard)netboard=1;
sprintf(s,"%s*.PKT",inbound);
if(!findfirst(s,&f,0)) { /* Got naked packet(s) */
do {
sprintf(s,"%s%s",inbound,f.ff_name);
crack_pkt(s);
} while(!findnext(&f));
}
x=0;
while(arcext[x]!=NULL) {
sprintf(s,"%s*.%s?",inbound,arcext[x]);
if(!findfirst(s,&f,0)) { /* Got archived mail */
do {
strcpy(s,inbound);
s[strlen(s)-1]=0;
if(crack_arc(s,f.ff_name)) continue;
else {
sprintf(ss,"%s*.PKT",inbound);
if(!findfirst(ss,&f,0)) { /* Got naked packet(s) */
unlink(s);
do {
sprintf(ss,"%s%s",inbound,f.ff_name);
crack_pkt(ss);
} while(!findnext(&f));
}
}
} while(!findnext(&f));
}
x++;
}
close_msg_files(); /* All done; pack the bags and go home */
report();
}
void pascal report (void) {
register int x;
printf("\n");
if(!totalmsgs) {
printf("No messages imported.\n");
return;
}
for(x=0;x<maxareas;x++) {
if(anum[x]) {
printf("Imported %u msgs to area #%u %s.\n",anum[x],marea[x].number,marea[x].name);
}
}
printf("\nTotal msgs imported: %lu\n",totalmsgs);
if(domail!=2 && domail!=4 && domail!=6) get_char();
}
int pascal crack_arc (char *in,char *arcname) {
char s[256];
sprintf(s,"%s /c UNARC.BAT %s %s",getenv("COMSPEC"),in,arcname);
do_spawn(s);
}
int pascal crack_pkt (char *pktname) {
register word x;
FILE *fp;
long pos;
long len;
char *buffer;
word buflen;
int temp;
pmnum=0;
fp=fopen(pktname,"rb");
if(!fp) return -1; /* Return Can't Open */
fseek(fp,0L,SEEK_END); /* Get packet size */
len=ftell(fp);
if(len<=(long)sizeof(struct _pkthdr)) {
fclose(fp);
unlink(pktname);
printf("\nShort packet discarded.\n");
return 0; /* Ignore 'short' packet */
}
fseek(fp,0L,SEEK_SET);
if((len-(long)sizeof(struct _pkthdr))<65533L) buflen=(word)((len-(long)sizeof(struct _pkthdr))+1L);
else buflen=65534; /* Set minimum buffer length */
buffer=(char *)malloc(buflen+1); /* Allocate text buffer */
if(!buffer) {
fclose(fp);
return -2; /* Return OOM */
}
fread(&pi,sizeof(struct _pkthdr),1,fp); /* Get packet header */
printf("\nPacket `%s' is from address %u:%u/%u.%u@%s\n",pktname,pi.orig_zone,pi.orig_net,pi.orig_node,pi.orig_point,pi.domain);
if(!strcmp(pi.domain,"XBBS")) {
printf("Mailerless point packet.\n");
mailerless=1;
}
else mailerless=0;
for(x=0;x<(word)noaddress;x++) {
if((pi.dest_zone==0 || pi.dest_zone==address[x]->zone) && (pi.dest_net==address[x]->net) && (pi.dest_node==address[x]->node) && (pi.dest_point==0 || pi.dest_point==address[x]->point)) {
curaddress.zone=address[x]->zone;
curaddress.net=address[x]->net;
curaddress.node=address[x]->node;
curaddress.point=address[x]->point;
strcpy(curaddress.domain,address[x]->domain);
break;
}
}
if((pi.dest_zone!=0 && pi.dest_zone!=curaddress.zone) || (pi.dest_net!=curaddress.net) || (pi.dest_node!=curaddress.node) || (pi.dest_point!=0 && pi.dest_point!=curaddress.point)) {
printf("Packet isn't ours; addressed to %u:%u/%u.%u\n",pi.dest_zone,pi.dest_net,pi.dest_node,pi.dest_point);
fclose(fp);
if(buffer)free(buffer);
/* return(forward_pkt(pktname)); */
move_2_safety(pktname);
return 0;
}
while(!feof(fp)) {
temp=get_msg(buflen,buffer,fp);
if(temp==-1) {
fclose(fp);
if(buffer)free(buffer);
move_2_safety(pktname);
return -3; /* Return 'minor' error */
}
if(temp<0) break; /* End of packet */
if(text==NULL || !*text) {
printf("\nNULL message discarded.\r");
continue; /* NULL message */
}
if(!temp) {
for(x=0;x<(word)noaddress;x++) {
if(xmsg.dest_net==address[x]->net && xmsg.dest==address[x]->node) {
curaddress.zone=address[x]->zone;
curaddress.net=address[x]->net;
curaddress.node=address[x]->node;
curaddress.point=address[x]->point;
strcpy(curaddress.domain,address[x]->domain);
break;
}
}
if(xmsg.dest_net==curaddress.net && xmsg.dest==curaddress.node) temp=import();
/* else forward_msg(buffer); */
if(temp) {
/* unknown_msg(); */
}
}
}
fclose(fp); /* Close packet */
unlink(pktname); /* Get rid of packet after unpacking */
if(buffer)free(buffer);
return 0; /* Return success */
}
static FILE *dataptr=NULL,*textptr=NULL;
void pascal close_msg_files (void) {
if(dataptr) fclose(dataptr);
if(textptr) fclose(textptr);
dataptr=textptr=NULL;
}
int pascal import () { /* Put msg in XBBS base */
register int x;
static word lastarea=0;
static word lastmarea;
word temp=0;
char textname[133];
char dataname[133];
if(area==NULL) temp=netboard;
else {
for(x=0;x<maxareas;x++) { /* Find the area tag */
if(!stricmp(area,marea[x].name)) {
temp=marea[x].number;
break;
}
}
lastmarea=x;
}
if(!temp) {
printf("\nMsg in unknown area \"%s\" ignored.\n",area);
return 1; /* Unknown area */
}
if(temp!=lastarea) {
if(dataptr)fclose(dataptr);
if(textptr)fclose(textptr);
lastarea=temp;
sprintf(textname,"%sXTEXT.%03x",path,temp);
sprintf(dataname,"%sXDATA.%03x",path,temp);
dataptr=fopen(dataname,"a+b");
textptr=fopen(textname,"a+b");
if(!dataptr || !textptr) {
if(dataptr)fclose(dataptr);
if(textptr)fclose(textptr);
dataptr=textptr=NULL;
printf("\nCan't open message base file(s)\n");
return 2; /* Error opening message area */
}
printf("\n");
}
if(!area) printf("\x1b[KPkt area NETMAIL (#%u) -=> Msg area %u (#%u)\r",++pmnum,lastarea,++anum[lastmarea]);
else printf("\x1b[KPkt area %s (#%u) -=> Msg area %u (#%u)\r",area,++pmnum,lastarea,++anum[lastmarea]);
totalmsgs++;
fseek(dataptr,0L,SEEK_END);
fseek(textptr,0L,SEEK_END);
xmsg.start=ftell(textptr);
if((marea[lastma